package com.kehongborui.staff.service.impl;

import com.kehongborui.staff.dao.IStaffDao;
import com.kehongborui.staff.dao.impl.StaffDao;
import com.kehongborui.staff.entity.Staff;
import com.kehongborui.staff.model.Condition;
import com.kehongborui.staff.model.Page;
import com.kehongborui.staff.service.IStaffService;

import java.util.List;

/**
 * @Description:   类描述
 * @Author:         XCQ
 * @email:          mr_xcq@163.com
 * @CreateDate:    2018-11-29 15:10
 * @UpdateUser:    username
 * @UpdateDate:    xxxx-xx-xx
 * @UpdateRemark:  修改内容
 * @Version:         1.0
*/
public class StaffService implements IStaffService {
   private StaffDao staffDao = new StaffDao();
    @Override
    public String create(Staff staff) {
        String result = staffDao.create(staff);
        return result;
    }

    @Override
    public String updateById(Staff staff) {
        String result = staffDao.updateById(staff);
        return result;
    }

    @Override
    public String deleteById(int id) {
        String result = staffDao.deleteById(id);
        return result;
    }

    @Override
    public List<Staff> queryAll(Condition condition, Page page) {
        List<Staff> staffs = staffDao.queryAll(condition, page);
        return  staffs;
    }

    @Override
    public Page queryNum(Condition condition) {
        Page page = new Page();
        int totalNum = staffDao.queryNum(condition);
        int totalPage = ( totalNum + page.getPageSize() -1 ) / page.getPageSize();
        page.setTotalNum(totalNum);
        page.setTotalPage(totalPage);
        return page;
    }

    @Override
    public Staff queryById(int id) {
        Staff staff = staffDao.queryById(id);
        return staff;
    }
}
